// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
const db = uniCloud.database()
const { result } = require("xzs-utils")
module.exports = {
	_before: function () { // 通用预处理器
		this.startTime = Date.now()
	},
	
	get: async function() {
		let res = await db.collection("xzs_product_nav").field({
			_createTime: false,
			orderid: false,
			state: false
		}).where({
			state: true
		}).orderBy("orderid", "asc").get()
		let arr = res.data.map(item => {
			return {
				_id: item._id,
				classname: item.classname,
				icon: item.icon.url
			}
		})
		return result(0, "success", arr)
		// return result(0, "success", res.data)
	},
	_after: function(error, result) {
		if (error) {
			throw error
		}
		let timeCoast = Date.now() - this.startTime
		result.timeCoast = timeCoast
		return result
	}
}
